package personal.leil.learning.undigraph;

import java.util.HashSet;

/**
 * 无向图顶点
 *
 * @author Leil
 * @version 1.0
 * @since 2024/1/22
 */
public class Vertex {


    /**
     * value of Vertex
     */
    public int value;

    /**
     * neighbors of current vertex
     */
    public HashSet<Vertex> neighbors;

    public HashSet<EdgeUndirected> edges;

    public Vertex(int value) {
        this.value = value;
        this.neighbors = new HashSet<>();
        this.edges = new HashSet<>();
    }

    /**
     * add neighbor for current vertex
     *
     * @param neighbor neighbor for adding
     */
    public void addNeighbor(Vertex neighbor) {
        this.neighbors.add(neighbor);
        neighbor.neighbors.add(this);
    }

    public void addEdge(EdgeUndirected edge) {
        this.edges.add(edge);
    }

    @Override
    public String toString() {
        return "Vertex[" + this.value + "]";
    }
}
